﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aribaccio;
using Aribaccio.Datum;
using BDPAutodetect.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BDPAutodetect.DataService
{
    /// <summary>
    /// 对象关系映射配置-检测记录数据
    /// </summary>
    public class TDetectRecordDataConfiguration : TBaseConfiguration, IEntityTypeConfiguration<TDetectRecordData>
    {
        /// 构造函数
        /// </summary>
        public TDetectRecordDataConfiguration(DBConnectType argConnectionType)
            : base(argConnectionType)
        {

        }

        /// <summary>
        /// 配置映射关系
        /// </summary>
        /// <param name="builder"></param>
        public void Configure(EntityTypeBuilder<TDetectRecordData> builder)
        {
            builder.ToTable("T_DetectRecord_Data");
            builder.Property(e => e.ID).HasColumnName("ID");
            builder.HasIndex(e => new { e.SampleDateTime, e.StationID, e.ParameterID, e.StatusFlag }, "IN_T_DetectRecord_Data");
            switch (this.ConnectionType)
            {
                case DBConnectType.SQLServer:
                    builder.Property(e => e.SampleDateTime).HasDefaultValueSql("(getdate())").HasColumnType("datetime");
                    builder.Property(e => e.SampleDuration).HasColumnName("SampleDuration");
                    builder.Property(e => e.StationID).HasColumnName("StationID");
                    builder.Property(e => e.ParameterID).HasColumnName("ParameterID");
                    builder.Property(e => e.Barcode).HasMaxLength(100).IsUnicode(false);
                    builder.Property(e => e.DebugModeStart).HasMaxLength(100).IsUnicode(false);
                    builder.Property(e => e.SoftwareVersion).HasMaxLength(100).IsUnicode(false);
                    builder.Property(e => e.WitchBarrelMicro).HasMaxLength(100).IsUnicode(false);
                    builder.Property(e => e.WitchTipping).HasMaxLength(100).IsUnicode(false);
                    builder.Property(e => e.NTCTemperature).HasColumnType("decimal(18, 0)").HasColumnName("NTCTemperature");
                    builder.Property(e => e.CompressorPower).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.CompressorCurrent).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.CompressorVoltage).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.CondenserFanPower).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.MotorPower).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.MotorCurrent).HasColumnType("decimal(18, 0)");              
                    builder.Property(e => e.MotorVoltage).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.EnvironmentTemperature).HasColumnType("decimal(18, 0)");
                    builder.Property(e => e.UserID).HasColumnName("UserID");
                    builder.Property(e => e.UpdateTime).HasDefaultValueSql("(getdate())").HasColumnType("datetime");
                    break;
                case DBConnectType.PostgreSQL:
                    builder.Property(e => e.SampleDateTime).HasDefaultValueSql("now()").HasColumnType("timestamp without time zone");
                    builder.Property(e => e.SampleDuration).HasDefaultValue(0);
                    builder.Property(e => e.StationID).HasDefaultValue(0).HasColumnName("StationID");
                    builder.Property(e => e.ParameterID).HasDefaultValue(0).HasColumnName("ParameterID");
                    builder.Property(e => e.Barcode).HasColumnType("character varying");
                    builder.Property(e => e.DebugModeStart).HasColumnType("character varying");
                    builder.Property(e => e.SoftwareVersion).HasColumnType("character varying");
                    builder.Property(e => e.WitchBarrelMicro).HasColumnType("character varying");
                    builder.Property(e => e.WitchTipping).HasColumnType("character varying");
                    builder.Property(e => e.NTCTemperature).HasColumnName("NTCTemperature");
                    builder.Property(e => e.UserID).HasDefaultValue(0).HasColumnName("UserID");
                    builder.Property(e => e.StatusFlag).HasDefaultValue(0);
                    builder.Property(e => e.UpdateTime).HasDefaultValueSql("now()").HasColumnType("timestamp without time zone");
                    break;
            }
        }
    }
}
